import {createRouter, createWebHashHistory, createWebHistory} from "vue-router";

const router = createRouter({
        history: createWebHistory(),
        routes: [
            {
                name: 'index',
                path: '/',
                component: () => import('@/views/index.vue'),
                redirect: '/express-check',
                children: [
                    {
                        name: 'test',
                        path: '/test',
                        component: () => import('@/views/test/index.vue'),
                        meta: {
                            title: '随心'
                        }
                    },
                    {
                        name: 'express-check',
                        path: '/express-check',
                        component: () => import('@/views/express-check/index.vue'),
                        meta: {
                            title: '物流查询'
                        }
                    },
                    {
                        name: 'dict',
                        path: '/dict',
                        component: () => import('@/views/dict/index.vue'),
                        meta: {
                            title: '新华字典'
                        }
                    },
                    {
                        name: 'toDay',
                        path: '/toDay',
                        component: () => import('@/views/toDay/index.vue'),
                        meta: {
                            title: '那年今日'
                        }
                    },
                    {
                        name: 'toDayTq',
                        path: '/toDayTq',
                        component: () => import('@/views/to-day-tq/index.vue'),
                        meta: {
                            title: '今日天气'
                        }
                    },
                    {
                        name: 'handle-image-ai',
                        path: '/handle-image-ai',
                        component: () => import('@/views/handle-image-ai/index.vue'),
                        meta: {
                            title: 'AI抠图'
                        }
                    },
                    {
                        name: 'search-qq-info',
                        path: '/search-qq-info',
                        component: () => import('@/views/search-qq-info/index.vue'),
                        meta: {
                            title: 'QQ查询'
                        }
                    },
                ]
            }
        ]
    }
)

router.beforeEach((to, from, next) => {
    window.$loadingBar.start()
    const {
        title
    } = to.meta
    document.title = title && (title) || ''
    next()
})

router.afterEach((to, from) => {
    window.$loadingBar.finish()
})

export default router
